<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;

use cmf\controller\AdminBaseController;
use think\Db;


class RankController extends AdminBaseController
{
    //列表
    public function index(){
        $list = db('rank')->select();
        $this->assign('list',$list);
       // dump($list);
       return $this->fetch(); 
    }

    //修改
    public function edit(){
        $id  = request()->param('id');
        if($this->request->isPost()){
            $data = request()->param();
            $id = $data['id'];
            unset($data['id']);
            $res = db('rank')->where('id',$id)->update($data);
            if($res){
                $this->success('修改成功');
            }else{
                $this->error('修改失败');
            }
           return;
        }
        $res = db('rank')->where('id',$id)->find();
        $this->assign('res',$res);
        return $this->fetch();
    }
   //添加等级
    public function add(){
        $data = request()->param();
        if($data){
            $data['create_time'] = time();
                $res = db('rank')->insert($data);
                if($res){
                    $this->success('添加成功');
                }else{
                    $this->error('添加失败');
                }
                return;
        }
        return $this->fetch();
    }

}